package com.liang.empty;



import lombok.Data;


@Data
public class Result<T> {


    //状态码  0.代表成功  其它代表失败状态码


    private Integer status;


    //提示信息


    private String msg;


    //响应数据


    private T data;


    //总记录数


    private Long count;


    /**
     * 构建带分页的返回
     * @param data
     * @param count
     * @return
     */
    public static Result buildSuccess(Object data, Long count){
        Result result=new Result();
        result.setStatus(0);
        result.setMsg("同步数据中");
        result.setData(data);
        result.setCount(count);
        return result;
    }



    /**
     * 构建普通数据的返回
     * @param data
     * @return
     */
    public static Result buildSuccess(Object data){
        return buildSuccess(data,null);
    }



    /**
     * 构建不需要携带数据的成功
     * @return
     */
    public static Result buildSuccess(){
        return buildSuccess(null);
    }


    /**
     * 构建失败的消息
     *@param code
     * @param msg
     * @return
     */
    public static Result buildFail(Integer code, String msg){
        Result result=new Result();
        result.setStatus(code);
        result.setMsg(msg);
        return result;
    }

    /**
     * 构建自带信息的返回
     */
    public static Result buildMessage(Object data, String msg , Integer code){
        Result result=new Result();
        result.setStatus(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

}